var Menu = function(){
	this.comp = null;
	var itens = [];
	
	this.bind = function(e){
		this.comp = $("<div class='menu'/>");
		
		for( var i = 0; i < itens.length; i++ ){
			var item = itens[i];
			
			var mnuI = $("<div class='menu-item'/>");
			mnuI.mouseenter(function(e){
				$(e.target).find(".menu-subitem").show('slow');
				$(e.target).mouseleave(function(){
					$(e.target).find(".menu-subitem").hide();
				});
			}).mouseleave(function(e){
				$(e.target).find(".menu-subitem").hide();
			});
			var mnuS = $("<span />");
			mnuS.text(item.label);
			mnuI.append(mnuS);
			var sub = $("<div class='menu-subitem'/>");
			mnuI.append(sub);
			
			var subItens = item.submenu.itens;
			for( var j = 0; j < subItens.length; j++ ){
				var smnu = subItens[j];
				var mnuI2 = $("<div />");
				var mnuS2 = $("<span />");
				mnuS2.text(smnu.label);
				var g = this.comp;
				mnuS2.click({c:this.comp,s:smnu},function(e){
					e.data.c.find(".menu-subitem").hide();
					e.data.s.onclick();
				});
				mnuI2.append(mnuS2);
				sub.append(mnuI2);
			}
			this.comp.append(mnuI);
		}
		var elem = null;
		if( e instanceof Object ){
			elem = e;
		}else{
			elem = $(e);
		}
		elem.append(this.comp);
	};
	
	this.addItem = function(label){
		var subMemu = new SubMemu();
		itens[itens.length] = {label:label, submenu:subMemu};;
		return subMemu;
	};
};

var SubMemu = function(){
	this.itens = [];
	this.addItem = function(label, onClick){
		this.itens[this.itens.length] = {label:label, onclick:onClick};
	};
};